$(function() {
	$("#header").load('header.html', function() {
		loadHeader(4)
	});
	$("#footer").load('footer.html', function(data, status, xhr) {});
	$("#tab").load('tab.html', function(data, status, xhr) {});
	//获取url中的参数
	function getUrlParam(name) {
		var reg = new RegExp("(^|&)" + name + "=([^&]*)(&|$)"); //构造一个含有目标参数的正则表达式对象
		var r = window.location.search.substr(1).match(reg); //匹配目标参数
		if(r != null) return unescape(r[2]);
		return null; //返回参数值
	}
	//接收URL中的参数
	var id = getUrlParam('id');
	console.log(id);

	$.ajax({
		url: host + '/NPLAPI/GetProductDetail',
		type: 'POST',
		dataType: 'JSON',
		data: {
			id: id
		},

		success: function(res) {
			var obj = res.data

			if(res.state) {
				$('.good-detail').append(
					`
				<div class="good-detail-pro">
				<div class='good-detail-img' style='background-image:url(${obj.mainimg})'></div>
				<div class="good-detail-txt">
					<div class="good-detail-good">${obj.name}</div>
					<div class='good-detail-tib'>
							<div>正品保障</div><div>七天包邮</div><div>极速发货</div>
					</div>
					<div class='good-detail-time'>秒杀时间:${obj.CreateTime}</div>
					<div class='good-rl'>
					
					</div>
					<div class='good-each'><ul class="good-detail-pro-txt"">
						<li>原价:${obj.sku[0].oriPrice}</li>
						<li>秒杀价:${obj.sku[0].miaoshajia}</li>
					</ul></div>
					
					
				</div>
			</div>
			<div class="good-detail-produce">${obj.detail}</div>
				`
				);
				var good = res.data.sku
				for(var i = 0; i < 1; i++) {
					$('.good-rl').append(
						`
						<div>${good[1].title}</div>
						`
					);

				}

				$('.good-rl div:eq(0)').addClass('active')
				$(".good-rl div").click(function() {
					console.log(id)
					$(this).addClass("active").siblings().removeClass("active");
				})
				//				<div class="button good-detail-compra"><a>立即购买</a></div>
			} else {

			}
		},
		error: function() {}
	});
});